/*
 * @Description:
 * @Author: Junhuang
 * @Date: 2022-07-14 11:19:33
 * @LastEditTime: 2022-07-14 11:24:08
 * @LastEditors: Junhuang
 * @Reference:
 */
'use strict';

const Service = require('egg').Service;

class LiveService extends Service {

  // 直播间是否存在
  async exist(id) {
    const { app } = this;
    return await app.model.Live.findOne({
      where: {
        id,
      },
    });
  }
  // 判断当前直播间是否可用，只有正在直播、直播暂停的直播间可以用
  async checkStatus(id) {
    const live = await this.exist(id);
    if (!live) {
      return '直播间不存在';
    }

    if (live.status === 0) {
      return '直播间未开播';
    }

    if (live.status === 3) {
      return '直播间已结束';
    }

    return false;
  }
}

module.exports = LiveService;
